package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GloableExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exceptionHandler(Exception e) {
        System.err.println("发生了异常"+e.getMessage());
        e.printStackTrace();
        Result result = new Result();
        result.setData(e.getMessage());
        result.setMessage(e.getMessage());
        result.setCode(500);
        return result;
    }
}
